package com.nf.health.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.MyDoctor;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

public class DoctorDetailItemAdapter extends BaseAdapter {
	private Context context;
	private String types;
	private List<MyDoctor> doctors;
	private int pos = -1;
	public DoctorDetailItemAdapter(Context context, List<MyDoctor> result) {
		this.context = context;
		this.doctors = result;
	}
	
	public void refreshPos(int position){
		this.pos = position;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		if (doctors != null) {
			return doctors.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return doctors.get(position);
	}

	@Override
	public long getItemId(int id) {
		return id;
	}

	@Override
	public View getView(final int position, View view, ViewGroup viewGroup) {
		final ViewHolder holder;
		if (view == null) {
			view = View.inflate(context, R.layout.my_doctor_item, null);
			holder = new ViewHolder();
			holder.doctor_icon = (ImageView) view.findViewById(R.id.doctor_icon);
			holder.doctor_name = (TextView) view.findViewById(R.id.doctor_name);
			holder.doctor_type = (TextView) view.findViewById(R.id.doctor_type);
			holder.cb_select = (CheckBox) view.findViewById(R.id.cb_select);
			holder.doctor_speciticalty = (TextView) view.findViewById(R.id.doctor_speciality_details);
			view.setTag(holder);

		} else {
			holder = (ViewHolder) view.getTag();
		}
		if(pos == position){
			holder.cb_select.setChecked(true);
		}else{
			holder.cb_select.setChecked(false);
		}
		holder.doctor_name.setText(doctors.get(position).getNick());

		holder.doctor_type.setText(doctors.get(position).getHospitalname());
		holder.doctor_speciticalty.setText("主治:"+ doctors.get(position).getExperience());
		ImageLoaderUtils.getinstance(context).getImage(holder.doctor_icon,doctors.get(position).getHimg(),R.drawable.default_square_image);
		return view;
	}

	class ViewHolder {
		ImageView doctor_icon;
		CheckBox cb_select;
		TextView doctor_name, doctor_type, doctor_speciticalty;
	}

}
